using System;
using System.IO;
using System.Windows;
using Qplus.beans;

namespace Qplus.Commands
{

    /**
     * 
     * 修改用户信息
     *
     *
     */
    public class ModifyUserCommand : AbsHeaderHttpCommand, HttpInputStreamProcessor
    {
        const String COMMAND = "ModifyUser";
        QUser user;
        int retry = 5;

        private String name;
        private String email;
        private String password;
        private String birth;
        private int sex;
        private int canStrangerChat;
        private int headType;
        private String headValue;
        //private File file;
        /**
         * @param command
         * @param uid
         * @param UKEY
         */
        public ModifyUserCommand(String uid, String UKEY, QUser user)
            : base(COMMAND, uid, UKEY)
        {
            this.user = user;
        }

        ///**
        // * 设置属性
        // * @param name名字
        // * @param email邮箱
        // * @param password密码
        // * @param age年龄
        // * @param sex性别
        // * @param canStrangerChat是否允许陌生人聊天
        // * @param headType头像类型
        // * @param headValue头像值
        // * @throws IOException 
        // */
        public void set(String name,
                String email,
                String password,
                String birth,
                int sex,
                int canStrangerChat,
                int headType,
                String headValue)//, File file)
        {
            setName(name);
            setEmail(email);
            setPassword(password);
            setBirth(birth);
            setSex(sex);
            setCanStrangerChat(canStrangerChat);
            setHeadType(headType);
            setHeadValue(headValue);

            //TODO
        }

        private void setName(String name)
        {
            addParams("Name", name);
        }

        private void setEmail(String email)
        {
            addParams("Mail", email);
        }

        private void setPassword(String password)
        {
            addParams("Password", password);
        }

        private void setBirth(String age)
        {
            addParams("Birthday", age);
        }

        private void setSex(int sex)
        {
            addParams("Sex", sex);
        }

        private void setCanStrangerChat(int canStrangerChat)
        {
            addParams("CanStrangerChat", canStrangerChat);
        }

        private void setHeadType(int headType)
        {
            addParams("HeadType", headType);
        }

        private void setHeadValue(String headValue)
        {
            addParams("HeadValue", headValue);
        }


        public override Boolean processInputStream(Stream responseStream)
        {

            //		UserInfo info = user.getInfo();
            //		info.setAge(age);
            //		info.setCanStrangerChat(canStrangerChat);
            //		info.setHeadType(headType);
            //		info.setHeadValue(headValue);
            //		info.setMail(email);
            //		info.setSex(sex);
            //		info.setUserName(name);
            //		info.notifyObservers();
            //密码修改了没保存
            return true;
        }

        public void onSuccess(int code)
        {
        }

        public void onFailed(int code)
        {
            //TODO
        }

        public HttpTask execute(String url)
        {
            return base.execute(url, this);
        }


        public override void onStart()
        {
            //TODO
        }
    }
}
